package test;
import java.io.File;
import java.io.IOException;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class UsePattern {
	public static void main(String[] args) throws IOException 
	{
		String s = "some text";

		Pattern pEnglishWord = Pattern.compile("\\G[a-z0-9A-Z]+");
		Pattern pChineseWord = Pattern.compile("\\G[\u4e00-\u9fa5]");
		
		Matcher m = pEnglishWord.matcher(s); // Any Pattern object can create
		Integer currentLoc = 0; // Begin at the start of the string
		while (currentLoc < s.length()) 
		{
			if (m.usePattern(pEnglishWord).find(currentLoc)) 
			{
				// have a word or number in m.group()
				// can now check for profanity, etc
				System.out.println(m.group());
				currentLoc = m.end(); // The 'current location' is now where the previous match ended
			}
			else if (m.usePattern(pChineseWord).find(currentLoc)) 
			{
				System.out.println(m.group());
				currentLoc = m.end(); // The 'current location' is now where the previous match ended
			}
			else
			{			
				// Nothing matched at this point, so skip the character
				currentLoc++;				
			}
		}
	}
}
